package tp.pr5.instructions;


import tp.pr5.NavigationModule;
import tp.pr5.RobotEngine;
import tp.pr5.instructions.exceptions.InstructionExecutionException;
import tp.pr5.instructions.exceptions.WrongInstructionFormatException;
import tp.pr5.items.ItemContainer;

/**
 * This Instruction shows the description of the current place and the items in it. This Instruction works if the user writes RADAR
 *
 */
public class RadarInstruction implements Instruction
{

	private NavigationModule navigation;
	
	/**
	 * Default constructor
	 */
	public RadarInstruction()
	{
		this.navigation = null;
	}
	
	/**
	 * Parses the String returning an instance of RadarInstruction or throwing a WrongInstructionFormatException()
	 * 
	 * @param cad string given
	 */
	@Override
	public Instruction parse(String cad) throws WrongInstructionFormatException 
	{
		cad = cad.toUpperCase();
		if(cad.equals("RADAR"))
		{
			return new RadarInstruction();
		}
		throw new WrongInstructionFormatException();
	}

	/**
	 * Fixes the current context, i.e., the robot engine and the navigation module
	 * 
	 * @param engine RobotEngine
	 * @param navigation NavigationModule
	 * @param robotContainer ItemContainer
	 * 
	 */
	@Override
	public void configureContext(RobotEngine engine, NavigationModule navigation, ItemContainer robotContainer) 
	{
		this.navigation = navigation;
	}

	/**
	 * Shows the current place description
	 */
	@Override
	public void execute() throws InstructionExecutionException
	{
		try
		{
			this.navigation.scanCurrentPlace();

		} catch(Exception e){
			throw new InstructionExecutionException();
		}
	}

	/**
	 * Returns a description of the Instruction syntax. The string does not end with the line separator. It is up to the caller adding it before printing
	 */
	@Override
	public String getHelp() 
	{
		return "RADAR";
	}

}
